package com.exc.controller;

import com.exc.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * @author Huang Min
 * @date 2020/8/27 19:34
 * @description
 */
@Controller
@RequestMapping("/u")
public class UserController {
    @RequestMapping(value = "/login",method = {RequestMethod.GET})
    public ModelAndView toLogin() {
        System.out.println("****登录接口****");
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("login");
        return modelAndView;
    }

    @RequestMapping(value = "/login.do",method = {RequestMethod.POST})
    public String login(String name, String password, HttpSession session) {
        System.out.println("****登录接口****");
        System.out.println("姓名:"+name+",密码:"+password);

        if (name.equals("admin") && password.equals("admin")){
            User user = new User(null,name,password);
            session.setAttribute("USER_IN_SESSION",user);

            System.out.println("跳转到列表查询页面");
            return "redirect:/r/list";
        }
        return "redirect:login";
    }

}
